package com.koron.order.risk.base.service.impl;


import cn.hutool.core.collection.CollUtil;
import com.koron.order.risk.base.bean.po.LineRiskDetailDefault;
import com.koron.order.risk.base.mapper.LineRiskDetailDefaultMapper;
import com.koron.order.risk.base.service.LineRiskDetailDefaultService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;

/**
 * 风险管控单-风险详情-默认(LineRiskDetailDefault)表服务实现类
 *
 * @author jzp
 * @since 2022-12-15 16:18:00
 */
@Service
public class LineRiskDetailDefaultServiceImpl implements LineRiskDetailDefaultService {

    /**
     * 通过ID查询单条数据
     *
     */
    @Override
    @TaskAnnotation("getById")
    public LineRiskDetailDefault getById(SessionFactory factory, String id) {
        LineRiskDetailDefaultMapper mapper = factory.getMapper(LineRiskDetailDefaultMapper.class);
        return mapper.selectById(id);
    }

    @Override
    @TaskAnnotation("getOneByRiskId")
    public LineRiskDetailDefault getOneByRiskId(SessionFactory factory, String riskId) {
        LineRiskDetailDefault lineRiskDetailDefault = new LineRiskDetailDefault();
        lineRiskDetailDefault.setRiskId(riskId);
        List<LineRiskDetailDefault> list = list(factory, lineRiskDetailDefault);
        return CollUtil.isEmpty(list) ? null : list.stream().max(Comparator.comparing(LineRiskDetailDefault::getId)).orElse(null);
    }

    /**
     * 查询所有数据
     *
     */
    @Override
    @TaskAnnotation("list")
    public List<LineRiskDetailDefault> list(SessionFactory factory, LineRiskDetailDefault lineRiskDetailDefault) {
        LineRiskDetailDefaultMapper mapper = factory.getMapper(LineRiskDetailDefaultMapper.class);
        return mapper.selectList(lineRiskDetailDefault);
    }

    /**
     * 新增数据
     *
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, LineRiskDetailDefault lineRiskDetailDefault) {
        LineRiskDetailDefaultMapper mapper = factory.getMapper(LineRiskDetailDefaultMapper.class);
        return mapper.insertOrUpdate(lineRiskDetailDefault) > 0;
    }

    /**
     * 修改数据
     *
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, LineRiskDetailDefault lineRiskDetailDefault) {
        LineRiskDetailDefaultMapper mapper = factory.getMapper(LineRiskDetailDefaultMapper.class);
        return mapper.update(lineRiskDetailDefault) > 0;
    }

    /**
     * 通过主键删除数据
     *
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        LineRiskDetailDefaultMapper mapper = factory.getMapper(LineRiskDetailDefaultMapper.class);
        return mapper.hidden(id) > 0;
    }
}
